package cn.hxzy.controller;


import cn.hxzy.common.Result;
import cn.hxzy.entity.carteam.DriverCar;
import cn.hxzy.entity.carteam.VehicleInformation;
import cn.hxzy.service.DriverCarService;
import cn.hxzy.service.VehicleInformationService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author hk
 * @since 2023-06-23
 */
@CrossOrigin
@RestController
@RequestMapping("/driverCar")
public class DriverCarController {
    @Autowired
    private DriverCarService driverCarService;
    @Autowired
    private VehicleInformationService vehicleInformationService;
    @GetMapping("/car/{carId}")
    public Result selectById(@PathVariable String carId){
        VehicleInformation byId = vehicleInformationService.getById(carId);
        return Result.ok().data1(byId);
    }
    @GetMapping("/user/{userId}")
     public Result selectByIdForCar(@PathVariable String userId ){
        QueryWrapper<DriverCar> wrapper = new QueryWrapper<>();
        wrapper.eq("driver_id",userId);
        List<DriverCar> list = driverCarService.list(wrapper);
        return Result.ok().data1(list);
    }
    @GetMapping("/selectOne/{userId}")
    public Result selectByIdForCar1(@PathVariable String userId){
        QueryWrapper<DriverCar> wrapper = new QueryWrapper<>();
        wrapper.eq("driver_id",userId);
        List<DriverCar> list = driverCarService.list(wrapper);
        System.out.println(list);
        if (list!=null){
            for (int i = 0; i < list.size(); i++) {
                if (list.get(i).getDefaultCarId()!=1){
                    list.remove(list.get(i));
                }
            }
        }
        return Result.ok().data1(list);
    }
}

